cmake_minimum_required(VERSION 3.2)
project(matxscript_tvm)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


IF (NOT CMAKE_MATX_COMPILE_FLAGS)
    MESSAGE(STATUS "CMAKE_MATX_COMPILE_FLAGS has not been set, use setup.py to install.")
    RETURN(-1)
ENDIF()
MESSAGE(STATUS "MatxScript Compile Flags: ${CMAKE_MATX_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_MATX_COMPILE_FLAGS}")

IF (NOT CMAKE_MATX_LINK_FLAGS)
    MESSAGE(STATUS "CMAKE_MATX_LINK_FLAGS has not been set, use setup.py to install.")
    RETURN(-1)
ENDIF()
MESSAGE(STATUS "MatxScript Link Flags: ${CMAKE_MATX_LINK_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_MATX_LINK_FLAGS}")

SET(TVM_ROOT "${TVM_PATH}")
SET(DMLC_CORE "${TVM_ROOT}/3rdparty/dmlc-core")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${TVM_ROOT}/include")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${DMLC_CORE}/include")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${TVM_ROOT}/3rdparty/dlpack/include")
SET(PKG_LDFLAGS "-L${TVM_ROOT}/build")

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/)

SET(CMAKE_CXX_FLAGS "-g -O2 -std=c++14 -fPIC -w -fpermissive  -pthread ${CMAKE_CXX_FLAGS} -ltvm_runtime ${PKG_LDFLAGS}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

FILE(GLOB_RECURSE MATXSCRIPT_TVM_SRCS RELATIVE ${CMAKE_SOURCE_DIR}  "src/*.cc")

ADD_LIBRARY(matx_tvm+tvmruntime SHARED ${MATXSCRIPT_TVM_SRCS})
